<template>
  <!-- 隐患处理 结束隐患-->
  <view class="container">
    <hidden-danger-info :detail="detail" />
    <view class="hidden-title">结束信息</view>
    <uni-forms ref="form" :model-value="endInfo" :rules="rules" labelWidth="70vw" labelPosition="top">
      <view class="background-white bor-top">
        <uni-forms-item name="cancelReason" label="结束原因">
          <textarea
            v-model="endInfo.cancelReason"
            class="text-area"
            placeholder-class="placeholder__style"
            placeholder="请根据实际情况简要说明结束原因(限50字)"
            maxlength="50"
          />
        </uni-forms-item>
      </view>
    </uni-forms>
    <view class="submit-group">
      <button @click="handleEnd" class="u-button-danger u-button block" :ripple="true">结束</button>
    </view>
  </view>
</template>

<script>
import { getHiddenDangerDetail } from '@/api/dbd/hiddenDangerBook'
import { cancelHiddenDangerCheckReport } from '@/api/dbd/hiddenDangerDeal'

import HiddenDangerInfo from './components/HiddenDangerInfo'

export default {
  components: {
    HiddenDangerInfo
  },
  data() {
    return {
      managerId: '',
      detail: {},
      now: Date.now(),
      area: '',
      endInfo: {
        cancelReason: ''
      },
      excludeIds: [],
      rules: {
        cancelReason: {
          rules: [
            {
              required: true,
              errorMessage: '必填项不能为空'
            }
          ]
        }
      }
    }
  },
  onReady() {
    this.$refs.form.setRules(this.rules)
  },
  onLoad({ managerId }) {
    this.managerId = managerId
    this.getDetail(managerId)
  },
  methods: {
    getDetail(managerId) {
      getHiddenDangerDetail(managerId).then((res) => {
        this.detail = res.data
      })
    },
    // 结束
    handleEnd() {
      this.$refs.form.validate().then((res) => {
        cancelHiddenDangerCheckReport({
          managerId: this.detail.managerId,
          cancelReason: this.endInfo.cancelReason
        }).then((res) => {
          uni.$emit('reload', true)
          uni.navigateBack({
            delta: 2
          })
        })
      })
    },
    // 取消
    handleCancel() {
      uni.navigateBack()
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  padding-bottom: 200rpx;

  .background-white {
    background-color: #fff;
    padding: 20rpx 30rpx;
    box-sizing: border-box;

    .uni-forms-item__label {
      color: #333;
      font-size: 30rpx;
    }

    .bor-btm {
      display: flex;
      border-bottom: 1px solid #d5d7e3;
    }

    .photo {
      display: flex;
      justify-content: space-between;

      image {
        width: 214rpx;
        height: 214rpx;
      }
    }
  }
}

.hidden-title {
  background: #f5f5f5;
  padding: 20rpx;
  color: #999;
}

.bor-top {
  border-top: 20rpx solid #f5f5f5;
}
</style>
